package com.xzy.spring.demo.proxy.statis;

import com.xzy.spring.demo.proxy.RealSubject;
import com.xzy.spring.demo.proxy.Subject;

/**
 * @author xzy
 * @date 2021/3/11 21:28
 * 说明：静态代理
 */
public class StaticProxy implements Subject {
    // 委托对象
    private final RealSubject realSubject;

    public StaticProxy(RealSubject realSubject) {
        this.realSubject = realSubject;
    }

    @Override
    public void request() {
        // 附加的代理逻辑
        System.out.println(">>>开始执行");

        // 目标方法
        realSubject.request();

        // 附加的代理逻辑
        System.out.println(">>>执行结束");
    }

    public static void main(String[] args) {
        RealSubject realSubject = new RealSubject();
        realSubject.request();
        System.out.println("");


        StaticProxy staticProxy = new StaticProxy(realSubject);
        staticProxy.request();
    }
}
